package com.aqielife.demo.example.lambda;

import java.util.stream.IntStream;

public class MinDemo<T> {
    public static void main(String[] args) {
        int nums[] = {1,43,2,9,-3,89,20};
        MinDemo demo = new MinDemo();
        demo.out(getMin(nums));

        // jdk8
        int min = IntStream.of(nums).min().getAsInt();
        demo.out(min);

        // 多线程并行
        int min2 = IntStream.of(nums).parallel().min().getAsInt();
        demo.out(min2);
    }
    public void out(T t){
        System.out.print(t);
    }

    private static int getMin(int[] nums) {
        int min = Integer.MAX_VALUE;    // 0x7fffffff
        for (int i : nums){
            if(i < min){
                min = i;
            }
        }
        return min ;
    }


}
